package com.wang.service;

import com.wang.entity.User;
import com.wang.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;


/**
 * Created by wangq on 2021/8/21.
 */
@Service
public class LoginService {
    @Autowired
    UserRepository userRepository;

    public String login(String username, String password, HttpSession httpSession) {
        User user = userRepository.findByUserName(username);
        if (user.getPassword().equals(password)) {
            httpSession.setAttribute("username",username+System.currentTimeMillis());
            return "redirect:/login/result";
        } else {
            // 非法用户返回登录页面
            System.out.println("非法，跳转");
            return "redirect:/login/toLogin";
        }
    }
}
